package hbr;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Test heading change of KillBot based on being fired on and wall hit.
 * 
 * @author Bryson Y. Hori
 */
public class TestHeading extends RobotTestBed {
  boolean wallHitCheck = false;
  double headingLast = 0;
  
  /**
   * Specifies that Corners and KillBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,hbr.KillBot";
  }
  
  /**
   * This test runs for 20 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 20;
  }
  
  /**
   * Checks the heading of KillBot to see if there is any change.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded (TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double heading = robot.getBodyHeading();
    
    if (headingLast == 0) {
      headingLast = heading;
    }
    else {
      if (headingLast != heading) {
        wallHitCheck = true;
      }
      headingLast = heading;
    }
  }
  
  /**
   * After the battle, check to see that heading has changed.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted (BattleCompletedEvent event) {
    assertTrue("Change dirrection when hit wall", wallHitCheck);
  }
}
